package com.taikang.hmp.hbusiness.diabetes.measure.family.action.intface;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taikang.hmp.frame.common.ErrorConstant;
import com.taikang.hmp.frame.common.TKException;
import com.taikang.hmp.frame.common.datastructre.Dto;
import com.taikang.hmp.frame.common.datastructre.support.BaseDto;
import com.taikang.hmp.frame.common.datastructre.support.ResponseDto;
import com.taikang.hmp.frame.common.web.action.BaseAction;
import com.taikang.hmp.frame.common.web.session.AppSessionFactory;
import com.taikang.hmp.frame.common.web.session.SessionBean;
import com.taikang.hmp.hbusiness.diabetes.measure.family.service.IFamilyService;
import com.taikang.hmp.hbusiness.diabetes.measure.guide.action.intface.GuideAction;

/** 
 * 家人管理
 * author:qrp
 * time:2015年12月16日 下午2:02:10
 */
public class FamilyAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private static Logger logger = LoggerFactory.getLogger(GuideAction.class);
	
	private IFamilyService familyService;
	
	public IFamilyService getFamilyService() {
		return familyService;
	}

	public void setFamilyService(IFamilyService familyService) {
		this.familyService = familyService;
	}

	public String executeAction() {
		if ("addFriend".equals(requestDto.getMethod())) { 
			logger.info("--【添加好友】: method addFriend --");
			return addFriend();
		} else if ("getFriendList".equals(requestDto.getMethod())) {
			logger.info("--【获取好友列表】: method getFriendList --");
			return getFriendList();
		} else if ("delFriend".equals(requestDto.getMethod())) {
			logger.info("--【删除好友】: method delFriend --");
			return delFriend();
		} else if ("confirmFriend".equals(requestDto.getMethod())) {
			logger.info("--【好友确认】: method confirmFriend --");
			return confirmFriend();
		} else {
			logger.info("executeAction 里没有配置"+ requestDto.getMethod() +"方法!");
			throw new TKException("no support method:" + requestDto.getMethod());
		}
	}
	
	/**
	 * 添加好友
	 * @return
	 */
	public String addFriend(){
		ResponseDto responseDto=new ResponseDto();
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		String temp = familyService.addFriend(paramDto);
		if(temp.equals("friendnotexit")){
			responseDto.addErrorCode(ErrorConstant.ADD_FRIEND_FAIL);
		}else if(temp.equals("isfriend")){
			responseDto.addErrorCode(ErrorConstant.IS_FRIEND);
		}
		super.setDataMap(responseDto);
		return SUCCESS;
	}
	/**
	 * 获取好友列表
	 * @return
	 */
	public String getFriendList(){
		
		ResponseDto responseDto = new ResponseDto();
		//获取参数
	    Dto paramDto = requestDto.getRequestlist().get(0);
	    paramDto = super.appendRequestBase(paramDto, requestDto);
	    
	    List<Dto> result = familyService.getFriendList(paramDto);	
	    Dto resultDto = new BaseDto();
		resultDto.put("resultlist", result);
		responseDto.pushResultDto(resultDto);
		//
		super.setDataMap(responseDto);
		
		return SUCCESS;
	}
	/**
	 * 删除好友
	 * @return
	 */
	public String delFriend(){
		ResponseDto responseDto=new ResponseDto();
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		familyService.delFriend(paramDto);
		super.setDataMap(responseDto);
		return SUCCESS;
	}
	/**
	 * 好友确认
	 * @return
	 */
	public String confirmFriend(){
		
		ResponseDto responseDto=new ResponseDto();
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		familyService.confirmFriend(paramDto);
		super.setDataMap(responseDto);
		return SUCCESS;
	}
		
}
